//
//  StatusRetweetedCell.swift
//  glzbowei
//
//  Created by 高伦展 on 2018/2/8.
//  Copyright © 2018年 glz. All rights reserved.
//

import UIKit

///转发微博的cell
class StatusRetweetedCell: StatusCell {

    //微博视图模型
    //如果继承父类的属性
    //1.需要override
    //2.不需要super
    //3。先执行父类的didSet,再执行子类的didSet -
   override var viewModel:StatusViewModel?{
         didSet{
            retweetedLabel.text = viewModel?.retweetedText
            
            picView.snp.updateConstraints { (make) in
                
                 let offset = (viewModel?.thumbnailUrls?.count ?? 0) > 0 ? StatusCellMargin:0
                 make.top.equalTo(retweetedLabel.snp.bottom).offset(offset)
            }
        }
    }
    
    //背景按钮
    private lazy var backButton:UIButton = {
        let button = UIButton();
        button.backgroundColor = UIColor(white:0.95,alpha:1.0);
        return button
    }()
    
    //转发标签
    private lazy var retweetedLabel :UILabel = UILabel(
        title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博",
        fontSize: 14,
        color: UIColor.darkGray,
        screenInset: StatusCellMargin)

}

//MARK: - 设置界面
extension StatusRetweetedCell{
    
    override func setupUI() {
        super.setupUI()
        
        contentView.insertSubview(backButton, belowSubview: picView)
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        
        backButton.snp.makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp.bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp.left)
            make.right.equalTo(contentView.snp.right)
            make.bottom.equalTo(bottomView.snp.top)
        }
        
        retweetedLabel.snp.makeConstraints { (make) in
            make.top.equalTo(backButton.snp.top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp.left).offset(StatusCellMargin)
        }
        
        picView.snp.makeConstraints { (make) in
            make.top.equalTo(retweetedLabel.snp.bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp.left)
            make.width.equalTo(300)
            make.height.equalTo(90)
            
        }
    }
}
